package com.huatai.bpmn.commom.job;

import com.alibaba.fastjson.JSONObject;
import com.huatai.bpmn.commom.util.WebSocketServer;
import com.huatai.bpmn.constant.PMPConstant;
import com.huatai.bpmn.entity.vo.YYTaskVo;
import com.huatai.bpmn.service.YYActivitiService;
import com.huatai.common.entity.UserInfo;
import com.huatai.common.httputil.HttpRequest;
import com.huatai.common.util.AuthUtil;
import com.huatai.common.util.ObjectUtil;
import com.huatai.user.dubbo.UserDubboApi;
import com.huatai.user.entity.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ScheduledTasks {
	@Autowired
	private YYActivitiService yyActivitiService;
	@Autowired
	private WebSocketServer webSocketServer;

	HashMap<String, HashMap<String, Integer>> userMap = new HashMap<>();
	/**
	 * 用户审批任务-定时推送任务给用户
	 */
    @Scheduled(cron = "0/3 * * * * ? ") // 每3秒执行一次
    public void checkTask() {
		ConcurrentHashMap<String, WebSocketServer> webSocketMap = webSocketServer.webSocketMap;
		if (ObjectUtil.isEmpty(webSocketMap)){
			return;
		}
		Set<Map.Entry<String, WebSocketServer>> entries = webSocketMap.entrySet();
		entries.forEach(x->{
			HashMap<String, Object> toDoTaskCount = yyActivitiService.findToDoTaskCount(x.getKey());
			webSocketMap.get(x.getKey()).sendMessage(JSONObject.toJSONString(toDoTaskCount));
		});
    }


}
